<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;

// 跨域设置
// header('Access-Control-Allow-Origin', '*');
// header('Access-Control-Allow-Credentials', 'true');
// Headers 可以根据实际情况进行改写。
// header('Access-Control-Allow-Headers', 'DNT,Keep-Alive,User-Agent,Cache-Control,Content-Type,Authorization');
$allowCrossDomain = [
    // 跨域配置，https://www.kancloud.cn/manual/thinkphp6_0/1037507
    'Access-Control-Allow-Origin'   => '*',
    'Access-Control-Allow-Methods'  => 'GET, POST, PATCH, PUT, DELETE',
    'Access-Control-Allow-Headers'  => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With'
];

Route::group('api/v1', function(){
    Route::get('test', function(){
        echo "this is a v1";
    });
})->allowCrossDomain($allowCrossDomain);

Route::group('api/v2', function(){
    Route::get('test', function(){
        echo "this is a v2";
    });
})->allowCrossDomain($allowCrossDomain)->middleware('throttle');